package beans;

import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import database.pack.DatabaseConnector;

public class BasketBeanDAO implements Serializable 
{
	private static final long serialVersionUID = 1L;
	private ArrayList<String> basket = new ArrayList<String>();
	
	public void addToBasket(String id)
	{
		try
		{
			DatabaseConnector databaseConnect = new DatabaseConnector();
			databaseConnect.connectToDatabase();
			Statement stat = databaseConnect.getConnection().createStatement();
			ResultSet basketItem =  stat.executeQuery("SELECT id,category,description,itemWeight,price FROM product WHERE id = " + id);
					
			while(basketItem.next())
			{
				basket.add(	basketItem.getString("id") + "/" + 
							basketItem.getString("category") + "/" +
							basketItem.getString("description") + "/" +
							basketItem.getString("itemWeight") + "/" +
							basketItem.getString("price")
							); // Adding category and description results to the array
			}
			basketItem.close();
			stat.close();
			databaseConnect.getConnection().close();
		}
		
		catch(SQLException | ClassNotFoundException e)
		{
			e.getMessage();
		}
	}
	
	public ArrayList<String> getBasket()
	{
		return basket;
	}
}
